﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.Data.SqlClient;
using ECONTACT.Controller;

namespace ECONTACT
{
    public partial class frmLop : Form
    {
        NamHocCtrl m_NamHocCtrl = new NamHocCtrl();
        KhoiLopCtrl m_KhoiLopCtrl = new KhoiLopCtrl();
        GiaoVienCtrl m_GiaoVienCtrl = new GiaoVienCtrl();
        LopCtrl m_LopCtrl = new LopCtrl();

        public frmLop()
        {
            InitializeComponent();
        }

        private void frmLop_Load(object sender, EventArgs e)
        {
            m_GiaoVienCtrl.HienThiComboBoxTen(cmbMaGiaoVien);
            m_KhoiLopCtrl.HienThiComboBoxTen(cmbMaKhoiLop);
            m_NamHocCtrl.HienThiComboBoxTen(cmbMaNamHoc);
            m_LopCtrl.HienThi(dGVLop, txtMaLop, txtTenLop, cmbMaKhoiLop, cmbMaNamHoc, cmbMaGiaoVien);
            DataService.OpenConnection();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            m_LopCtrl.LuuLop(txtTenLop.Text, cmbMaKhoiLop.SelectedValue.ToString(), cmbMaNamHoc.SelectedValue.ToString(), cmbMaGiaoVien.SelectedValue.ToString());
            m_LopCtrl.HienThi(dGVLop, txtMaLop, txtTenLop, cmbMaKhoiLop, cmbMaNamHoc, cmbMaGiaoVien);
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            m_LopCtrl.UpdateLop(txtMaLop.Text, txtTenLop.Text, cmbMaKhoiLop.SelectedValue.ToString(), cmbMaNamHoc.SelectedValue.ToString(), cmbMaGiaoVien.SelectedValue.ToString());
            m_LopCtrl.HienThi(dGVLop, txtMaLop, txtTenLop, cmbMaKhoiLop, cmbMaNamHoc, cmbMaGiaoVien);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (dGVLop.RowCount == 0)
            {
                MessageBox.Show("Bạn chưa chọn dòng nào làm sao xóa!", "Thông báo");
            }
            else if (MessageBoxEx.Show("Bạn có chắc là xóa thiệt hok ?", "DELETE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                m_LopCtrl.DeleteLop(txtMaLop.Text);
                m_LopCtrl.HienThi(dGVLop, txtMaLop, txtTenLop, cmbMaKhoiLop, cmbMaNamHoc, cmbMaGiaoVien);
            }
        }
    }
}
